﻿$(document).ready(function () {
    $('#frm-adduser').submit(function () {
        App.blockUI($('body'));
        $.ajax({
            url: "/users/adduser",
            type: "POST",
            data: $(this).serialize(),
            success: function (data) {
                if (data.success == 1) {
                    alert(data.message);
                    window.opener.location.reload(true);
                    window.close();
                }
                alert(data.message);
                App.unblockUI('body');
            },
            error: function () {
                //alert("Error!");
                App.unblockUI('body');
            }
        });
        return false;
    });


    $('#managerpicker').submit(function () {
        App.blockUI($('body'));
        $.ajax({
            url: "/Users/managerpicker",
            type: "POST",
            data: $(this).serialize(),
            success: function (data) {
                if (data.success == 1) {
                    alert("Success full!");
                    App.unblockUI('body');
                    $("#ManagerPicker").modal("hide");
                }
            },
            error: function () {
                alert("Error!");
                App.unblockUI('body');
            }

        });
        return false;
    });
    
    $('#managerdriver').submit(function () {
        App.blockUI($('body'));
        $.ajax({
            url: "/Users/managerdriver",
            type: "POST",
            data: $(this).serialize(),
            success: function (data) {
                if (data.success == 1) {
                    alert("Success full!");
                    App.unblockUI('body');
                    $("#ManagerDriver").modal("hide");
                }
            },
            error: function () {
                alert("Error!");
                App.unblockUI('body');
            }

        });
        return false;
    });
    $('#manager-permission').submit(function () {
        App.blockUI('body');
       
    });
});

function EditUser(id, w, h) {
    PopupCenter('/users/adduser?userid=' + id, w, h);
}

function ResetPassword(userid, username) {

    if (!confirm("Are you sure you wish to reset the password for " + username + "?")) {
        return false;
    }
    App.blockUI('body');
    $.ajax({
        url: "/Users/ResetPassword?userID=" + userid,
        data: $(this).serialize(),
        success: function (data) {
            if (data.success == 1) {
                alert(data.message);
                window.close();
                App.unblockUI('body');
            }
        },
        error: function () {
            alert("error");
            App.unblockUI('body');
        }
    });

}

function checkconfirm() {
    if (!confirm("Are you sure you wish to revoke permissions ?")) {
        return false;
    }
 
    $('#manager-permission').submit();
   
}


function ChangeListpermission() {

    if ($('.checkall').is(':checked')) {
        $('.cklistpermission').prop('checked', true);
    } else {
        $('.cklistpermission').prop('checked', false);
    }
}

function ExportManagerPermission(userid) {
    App.blockUI('body');
    $.ajax({
        url: '/users/ExportManagerPermission/?userid=' + userid,
    });

    App.unblockUI('body');

}

